#include <windows.h>

BOOL EscalatePrivilege()
{
    HANDLE hToken = NULL;
    LUID luid = { 0 };
    TOKEN_PRIVILEGES TokenPrivileges = { 0 };
    BOOL bRet = FALSE;
    DWORD dwRet;

    do
    {
        bRet = ::OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
        if (!bRet) break;

        bRet = ::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid);
        if (!bRet) break;

        TokenPrivileges.PrivilegeCount = 1;
        TokenPrivileges.Privileges[0].Luid = luid;
        TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        bRet = ::AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, 0, NULL, NULL);
        if (!bRet) break;

        dwRet = ::GetLastError();
        if (ERROR_NOT_ALL_ASSIGNED == dwRet)
            bRet = FALSE;
        else
            bRet = TRUE;

    } while (FALSE);

    return bRet;
}